<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<script type="text/javascript">

function chkValue(text){ 
	if(text == undefined || text == null || text.trim() == ""){
		alert('정확히 입력한 후 체크하세요');
	} else {
		if (typeof(text) != "string"){ 
			alert('문자열만 체크할 수 있습니다.');
		} else {
			var _chk = true; _sp = /\s+/;var msg="";
			//첫글자는 여기서 일단 체크
				var ch = text[0].charCodeAt();
				var pt = (ch >= 0x61 && ch <= 0x7A) || (ch >= 0x41 && ch <= 0x5A)
				_chk = _chk && pt
				if(!_chk) {msg = "첫 글자는 영어 대~소문자만 가능합니다.\n";}
				
			//두번째부터는 숫자도 들어간다.
			for(var i=1; i<text.length;i++){
				ch = text[i].charCodeAt();
				pt = ((ch >= 0x61 && ch <= 0x7A) || (ch >= 0x41 && ch <= 0x5A) || (ch >= 0x30 && ch <= 0x39))
				//alert(text[i] + " = " + pt);
				_chk = _chk && pt
			}//end for//alert("최종결과 " + _chk);
			if(!_chk) {
				msg = msg + "영어 대,소문자와 숫자의 조합으로 만들어주세요.";
				alert(msg);
			}
			return _chk;
		}//end else - if
	}//end if
}
	function number1() {
		var b = document.writeParking;
		if (!((event.keyCode >= 48 && event.keyCode <= 57)
				|| (event.keyCode >= 96 && event.keyCode <= 105) || event.keyCode == 8)) {
			alert('숫자만 입력해 주세요!');
			b.p_cost.value = "";
			event.returnValue = false;
		}
	}
	function number2() {
		var b = document.writeParking;
		if (!((event.keyCode >= 48 && event.keyCode <= 57)
				|| (event.keyCode >= 96 && event.keyCode <= 105) || event.keyCode == 8)) {
			alert('숫자만 입력해 주세요!');
			b.p_count.value = "";
			event.returnValue = false;
		}
	}

	  function fn_maskPhone(obj) { 
        obj.value =  fn_PhoneNumStr(obj.value); 
    } 
    function fn_PhoneNumStr(str){ 
        var RegNotNum  = /[^0-9]/g; 
        var RegPhoneNum = ""; 
        var DataForm   = ""; 
        // return blank  
        var b = document.writeParking;
		if (!((event.keyCode >= 48 && event.keyCode <= 57)
				|| (event.keyCode >= 96 && event.keyCode <= 105) || event.keyCode == 8)) {
			alert('숫자만 입력해 주세요!');
			b.p_cost.value = "";
			event.returnValue = false;
		}
        if( str == "" || str == null ) return ""; 
        // delete not number
        str = str.replace(RegNotNum,''); 
        if( str.length < 4 ) return str; 
        if( str.length > 3 && str.length < 7 ) { 
               DataForm = "$1-$2"; 
            RegPhoneNum = /([0-9]{3})([0-9]+)/; 
        } else if(str.length == 7 ) {
            DataForm = "$1-$2"; 
            RegPhoneNum = /([0-9]{3})([0-9]{4})/; 
        } else if(str.length == 8 ) {
            DataForm = "$1-$2-$3"; 
            RegPhoneNum = /([0-9]{3})([0-9]{4})([0-9]+)/; 
        } else if(str.length == 9 ) {
            DataForm = "$1-$2-$3"; 
            RegPhoneNum = /([0-9]{3})([0-9]{4})([0-9]+)/; 
        } else if(str.length == 10){ 
            if(str.substring(0,2)=="02"){
                DataForm = "$1-$2-$3"; 
                RegPhoneNum = /([0-9]{3})([0-9]{4})([0-9]+)/; 
            }else{
                DataForm = "$1-$2-$3"; 
                RegPhoneNum = /([0-9]{3})([0-9]{4})([0-9]+)/;
            }
        } else if(str.length > 10){ 
            DataForm = "$1-$2-$3"; 
            RegPhoneNum = /([0-9]{3})([0-9]{4})([0-9]+)/; 
        } 
        if(RegPhoneNum != ''){
            while( RegPhoneNum.test(str) ) {  
                str = str.replace(RegPhoneNum, DataForm);  
            }
        }
        return str; 
    } 
</script>

<style type="text/css">
	fieldset{
		width: 800px;
	}
	fieldset ul{
		line-height 
		list-style: none;
		padding:0;
		margin:2px;
	}
	fieldset ul li{
		margin:0 0 9px 0;
		padding:0;
	}
	fieldset input{
		width: 200px;
	}
	input[type="submit"]{
		width: 120px;
		font-family: "맑은 고딕";
	}
	input[type="button"]{
		width: 120px;
		font-family: "맑은 고딕";
	}
	legend{
		font-family: "맑은 고딕";
		font-size: 20px;
		color: green;
	}
	#shadow{
		position: inherit;
		box-shadow:5px 5px 10px #000;
		-webkit-box-shadow:5px 5px 10px #000;
		-moz-box-shadow:5px 5px 10px #000;
	}
</style>
<br>
<div style="width: 827px;" id="shadow">
<form action="write.do" method="post" name = "writeParking" onsubmit="return chkValue(this.form)">

<fieldset>
	<legend>수정해주세요</legend><br>
	<ul>
		<li>
			<label for="name" style="color: navy;">소유자</label>
			<input type="text" name="name" id="name" size="50" value="${param.m_name }" disabled>
		</li>
		<li>
			<label for="name">주차장 이름</label>
			<input type="text" name="p_name" value="${parking.p_name }" size="50" disabled>
		</li>
		<li>
			<label for="name">주소</label>
			<input type="text" name="p_addr" id="p_addr" size="50" value="${parking.p_addr }" autofocus placeholder="주소입력.예)oo시 oo구">
		</li>
		<li>
			<label for="name">전화번호</label>
			<input type="text" name="p_phone" id="p_phone"maxlength="13" size="50" value="${parking.p_phone }"
			onKeyDown="fn_maskPhone(this);" onKeyUp="fn_maskPhone(this);"  placeholder="숫자만 입력.예) 1234123456789">
		</li>
		<li>
			<label for="name">주차가능대수</label>
			<input type="text" name="p_count" id="p_count" value="${parking.p_count }" size="50" onkeydown="number2()"   placeholder="숫자만 입력.예) 100">
		</li>
		<li>
			<label for="name">이용단가(단위:분)</label>
			<input type="text" name="p_cost" size="50" value="${parking.p_cost }" onkeydown="number1()" id="p_cost" onkeydown="number1()"  placeholder="숫자만 입력.예) 500">
		</li>
		<li align="center">
				<input type="submit" value="수정">
				<input type="button" value="취소" onclick="location.href='write.do'">
		</li>
	</ul>
	</fieldset>
</form>
</div>